package org.mitoma.logger.client;

import org.mitoma.logger.shared.AuthInfo;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

public class MainPanel extends Composite {

  private static MainPanelUiBinder uiBinder = GWT
                                                .create(MainPanelUiBinder.class);

  interface MainPanelUiBinder extends UiBinder<Widget, MainPanel> {
  }

  @UiField
  public SimplePanel login;
  @UiField
  public SimplePanel content;

  public MainPanel() {
    initWidget(uiBinder.createAndBindUi(this));
  }

  @UiHandler("logo")
  void logoClick(ClickEvent event) {
    GlobalRepository.getService().isLoggedIn(new AsyncCallback<AuthInfo>() {

      @Override
      public void onSuccess(AuthInfo result) {
        GlobalRepository.moveToTop();
      }

      @Override
      public void onFailure(Throwable caught) {
        Window.Location.reload();
      }
    });
  }

}
